
<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.paths.core }}css/login.css?v={{ layui.admin.v }}" media="all">
</script>


<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>
                <img src="/res/style/imgs/billtong_64.png" />
                <span>票据通</span>
            </h2>
            <p> </p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <script type="text/html" template>
                {{# if(layui.router().search.type === 'resetpass'){ }}
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
                    <input type="text" name="phonenumber" id="LAY-user-login-cellphone" lay-verify="required|phone" placeholder="请输入注册时的手机号" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-smscode"></label>
                            <input type="text" name="verificationcode" id="LAY-user-login-smscode" lay-verify="required" placeholder="短信验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="LAY-user-forget-getsmscode">获取验证码</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="passwd" id="LAY-user-login-password" lay-verify="pass" placeholder="新密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
                    <input type="password" name="confirmpasswd" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-forget-resetpass" id="btn-resetpass">重置密码</button>
                </div>
                <div class="layui-trans layui-form-item">
                    <a lay-href="/user/login" class="layadmin-user-jump-change layadmin-link layui-hide-xs">返回登录</a>
                </div>
                {{# } else { }}
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
                    <input type="text" name="cellphone" id="LAY-user-login-cellphone" lay-verify="phone" placeholder="请输入注册时的手机号" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img src="https://www.oschina.net/action/user/captcha" class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-smscode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-smscode" lay-verify="required" placeholder="短信验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="LAY-user-forget-getsmscode">获取验证码</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-forget-submit">找回密码</button>
                </div>
                {{# } }}
            </script>

        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">
        <p>Copyright © 2024.All Rights Reserved.</p>
    </div>

</div>

<script>
    layui.use(['admin', 'form', 'user'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router();

        form.render();
        console.log(setter);

        //回车实现登录
        $(".layui-input").keydown(function (e) {
            if (e.which == 13) {
                $("#btn-resetpass").click();
            }
        });

        //发送短信验证码
        admin.sendAuthCode({
            elem: '#LAY-user-forget-getsmscode'
            , elemPhone: '#LAY-user-login-cellphone'
            , elemVercode: '#LAY-user-login-vercode'
            , ajax: {
                url: setter.baseConfig.apiHost + '/api/sms/sendvercode?smsSceneType=2' //实际使用请改成服务端真实接口
            }
        });

        //找回密码下一步
        form.on('submit(LAY-user-forget-submit)', function (obj) {
            var field = obj.field;

            //请求接口
            admin.req({
                url: './res/json/user/forget.js' //实际使用请改成服务端真实接口
                , data: field
                , done: function (res) {
                    location.hash = router.href + '/type=resetpass';
                }
            });

            return false;
        });

        //重置密码
        form.on('submit(LAY-user-forget-resetpass)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.passwd !== field.confirmpasswd) {
                return layer.msg('两次密码输入不一致');
            }

            //请求接口
            $.ajax({
                url: setter.baseConfig.apiHost + '/api/account/resetpasswd' //实际使用请改成服务端真实接口
                , type: 'post'
                , contentType: "application/json"
                , data: JSON.stringify(field)
                , success: function (res) {
                    layer.msg('重置密码成功', {
                        offset: '15px'
                        , icon: 1
                        , time: 3000
                    }, function () {
                        location.hash = '/user/login'; //跳转到登入页
                    });
                }
            });

            return false;
        });        

    });
</script>